<template>
  <div>
    <lan-dialog
      :config="editConfig"
      :formData="editFormData"
    >
      <template #slot="scope">
        <el-input
          v-model="scope.data.slot"
          class="form-input"
        ></el-input>
      </template>
    </lan-dialog>
  </div>
</template>

<script>
import lanDialog from '../../../components/lanDialog';
import moment from 'moment';
import { MomentFormat, SortType } from '../../../constants/common';
import { Message, MessageBox } from 'element-ui';
import { parseError } from '../../../utils';
import { updateDeviceParameterApi } from '../../../api/deviceParameter';
export default {
  components: {
    lanDialog
  },
  data() {
    return {
      editConfig: {
        labelWidth: 200,
        dialogVisible: false,
        title: '修改设备类型参数',
        type: 'edit',
        inline: false,
        formList: [
          {
            name: 'name',
            label: '名称',
            type: 'input',
            placeholder: '请输入设备参数名称',
            required: true,
            tooltip: '设备类型参数的关键字，关键字不能重复',
            width: 300
          },
          {
            name: 'displayName',
            label: '显示名称',
            type: 'input',
            placeholder: '请输入设备参数显示名称',
            required: true,
            tooltip: '设备类型参数的显示名称',
            width: 300
          },
          {
            name: 'unit',
            label: '单位',
            type: 'input',
            placeholder: '请输入设备参数单位',
            tooltip: '每个设备类型参数的计量单位',
            width: 300
          },
          {
            name: 'description',
            label: '描述',
            type: 'input',
            placeholder: '请输入设备参数描述',
            tooltip: '每个设备类型参数的描述信息',
            width: 300
          }
        ],
        buttons: [
          {
            text: '取消',
            icon: '',
            type: '',
            method: () => {
              this.editConfig.dialogVisible = false;
            }
          },
          {
            text: '确认',
            icon: '',
            type: 'primary',
            method: row => {
              this.update();
              this.editConfig.dialogVisible = false;
            }
          }
        ]
      },

      editFormData: {
        id: '',
        name: '',
        displayName: '',
        unit: '',
        description: ''
      }
    };
  },
  methods: {
    search() {
      this.$emit('search');
    },
    showEditDialog(row) {
      this.editFormData.id = row.id;
      this.editFormData.name = row.name;
      this.editFormData.displayName = row.displayName;
      this.editFormData.unit = row.unit;
      this.editFormData.description = row.description;
      this.editConfig.dialogVisible = true;
    },
    update() {
      this.btnLoading = true;
      updateDeviceParameterApi(this.editFormData.id, this.editFormData.name, this.editFormData.displayName, this.editFormData.unit, this.editFormData.description)
        .then(res => {
          Message.success('更新成功');
          this.dialogVisible = false;
          this.search();
        })
        .catch(error => Message.error(parseError(error)))
        .finally(() => (this.btnLoading = false));
    }
  }
};
</script>

<style lang="scss" scoped>
/deep/.el-form-item {
  margin-bottom: 22px !important;
}
</style>

